package com.atguigu.srb.core.controller.admin;

import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.query.UserInfoQuery;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: Bright
 * @Date: 2022-04-17 20:33
 * @Description: com.atguigu.srb.core.controller.admin
 * 用户管理* @version: 1.0
 */

@Slf4j
@RestController
@Api(tags = "用户管理")
@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {

    @Resource
    UserInfoService userInfoService;

    @ApiOperation(value = "查询用户")
    @GetMapping("/list/{page}/{limit}")
    public R list(
            @ApiParam(value = "单前页码", required = true)
            @PathVariable
                    Integer page,
            @ApiParam(value = "每页数量", required = true)
            @PathVariable
                    Integer limit,
            @ApiParam(value = "搜索对象")
                    UserInfoQuery userInfoQuery) {
        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.listData(pageParam, userInfoQuery);
        return R.ok().data("pageModel", pageModel);

    }

    @ApiOperation(value = "锁定和解锁")
    @PutMapping("/lock/{id}/{status}")
    public R lock(
            @ApiParam(value = "用户id", required = true)
            @PathVariable Long id,
            @ApiParam(value = "状态:0锁定,1解锁", required = true)
            @PathVariable Integer status) {
        userInfoService.lock(id,status);
        return R.ok().message(status==0?"锁定成功":"解锁成功");

    }


}


















